import Vue from 'vue'
import Router from 'vue-router'

import login from '@/views/main/Login'
import main from '@/views/main/'
import scale from '@/views/main/Screen.vue'
import home from '@/views/module/home/'
import homeScale from '@/views/module/screen/index.vue'
Vue.use(Router)
const originalPush = Router.prototype.push

Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const createRouter = () => new Router({
  routes: [{
    path: '/login',
    component: login
  },
  {
    path: '',
    redirect: '/index',
    component: main,
    children: [
      {
        path: '/index',
        name: 'HOME',
        component: home
      },
      {
        path: '/message',
        name: 'MENU_MESSAGE_MANAGER',
        component: () => import('@/views/module/system/message/index')
      }
    ]
  }, {
    path: '/screen',
    component: scale,
    children: [{
      path: '',
      component: homeScale
    }]
  }]
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
